﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Fast.Framework.Models;

namespace Fast.Framework.Interfaces
{

    /// <summary>
    /// 数据库上下文接口类
    /// </summary>
    public interface IDbContext : IDisposable, ITenant
    {
        /// <summary>
        /// 上下文Id
        /// </summary>
        Guid ContextId { get; }

        /// <summary>
        /// Ado
        /// </summary>
        IAdo Ado { get; }

        /// <summary>
        /// Aop
        /// </summary>
        IAop Aop { get; }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        IInsert<T> Insert<T>(T entity) where T : class;

        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keyValues">键值</param>
        /// <returns></returns>
        IInsert<T> Insert<T>(Dictionary<string, object> keyValues) where T : class;

        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entityList">实体列表</param>
        /// <returns></returns>
        IInsert<T> Insert<T>(List<T> entityList) where T : class;

        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dictionaryList">字典列表</param>
        /// <returns></returns>
        IInsert<T> Insert<T>(List<Dictionary<string, object>> dictionaryList) where T : class;

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IDelete<T> Delete<T>() where T : class;

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">对象(这是一个虚拟对象主要是为了匿名类型可以使用Where方法)</param>
        /// <returns></returns>
        IDelete<T> Delete<T>(T obj) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IUpdate<T> Update<T>() where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        IUpdate<T> Update<T>(T entity) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keyValues">键值</param>
        /// <returns></returns>
        IUpdate<T> Update<T>(Dictionary<string, object> keyValues) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entityList">实体列表</param>
        /// <returns></returns>
        IUpdate<T> Update<T>(List<T> entityList) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dictionaryList">字典列表</param>
        /// <returns></returns>
        IUpdate<T> Update<T>(List<Dictionary<string, object>> dictionaryList) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        IUpdate<T> Update<T>(Expression<Func<T, T>> expression) where T : class;

        /// <summary>
        /// 大数据
        /// </summary>
        /// <returns></returns>
        IBigData BigData();

        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IQuery<T> Query<T>() where T : class, new();

        /// <summary>
        /// 子查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query">查询对象</param>
        /// <returns></returns>
        T SubQuery<T>(IQuery query);

        /// <summary>
        /// 联合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T> Union<T>(params IQuery<T>[] querys) where T : class;

        /// <summary>
        /// 联合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T> Union<T>(List<IQuery<T>> querys) where T : class;

        /// <summary>
        /// 联合所有
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T> UnionAll<T>(params IQuery<T>[] querys) where T : class;

        /// <summary>
        /// 联合所有
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T> UnionAll<T>(List<IQuery<T>> querys) where T : class;
    }
}
